package edu.sandau.b230111.b23011125.Service.Impl;

import edu.sandau.b230111.b23011125.Global.GlobalEnum;
import edu.sandau.b230111.b23011125.Model.Problem;
import edu.sandau.b230111.b23011125.Repository.ProblemRepository;
import edu.sandau.b230111.b23011125.Service.ProblemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

@Service
public class ProblemServiceImpl implements ProblemService {
    @Autowired
    private ProblemRepository problemRepository;

    @Override
    public Problem queryProblemById(String problemid) {
        return problemRepository.getReferenceById(problemid);
    }

    @Override
    public Page<Problem> queryAllProblem(Integer pageNum,Integer pageSize) {
        Pageable page = PageRequest.of(pageNum,pageSize);
        return problemRepository.findAll(page);
    }

    @Override
    public GlobalEnum.OperateResult modifyProblem(Problem problem) {
        return null;
    }

    @Override
    public GlobalEnum.OperateResult deleteProblem(String problemid) {
        problemRepository.deleteById(problemid);
        return GlobalEnum.OperateResult.SUCC;
    }

    @Override
    public GlobalEnum.OperateResult addProblem(Problem problem) {
        problemRepository.save(problem);
        return GlobalEnum.OperateResult.SUCC;
    }
}
